<?php 
// ----------------------------------------------------------------
// Owner class represents the owner of the restaurant.
// ----------------------------------------------------------------	
	class Owner
	{
		private $username ='N/A';
		private $password = 'N/A';
		//private $DTB;
		
		public function __construct()
		{
			$this->username = 'N/A';
			$this->password = 'N/A';
		}
		
		/*private function __construct($ownername, $pass)
		{
			$this->username = $ownername;
			$this->password = $pass;
			$this->DTB =  dbHandler::getInstance();
		}*/
		
		public function getOwner($user, $pass)
		{
			$DTB = dbHandler::getInstance();
			$query = "SELECT * FROM owner WHERE name = '$user' AND password = '$pass'"; 
			$result = $DTB->query($query);
			$owner = new Owner();
			//return $result;
			while($row = mysql_fetch_array($result))
			{
				$owner->username = mysql_result($result,0,'name');
				$owner->password = mysql_result($result,0,'password');
			}
		
			if($owner->username == $user && $owner->password == $pass)
			{
				return $owner;
			}
			else 
			{
				return $owner;
			}
		}
		
		public function getPassword()
		{
			return $this->password;
		}
	
		public function getName()
		{
			return $this->username;
		}	

		public function ViewUnassignOrder()
		{
			$DTB = dbHandler::getInstance();
			$query = "SELECT order_no FROM orders WHERE Assign = '0' AND is_Complete = 'No'";
			$result = $DTB->query($query);
			$html = "";
			$html = "<select name = UnAssignOrder>";
	  		while($row = mysql_fetch_array($result))
	  		{
	  			$orderNo = $row['order_no'];
	  			$html .= '<option value='.$orderNo.'>'.'Order # '.$orderNo.'</option>';
	  		}
	  		$html .= "</select>";
	  		return $html;
		}
		public function ViewSelectOrder($orderno)
		{
			$DTB = dbHandler::getInstance();
			$query = "SELECT * FROM orders WHERE order_no = '$orderno'";
			$result = $DTB->query($query);
			while($row = mysql_fetch_array($result))
	  		{
	  			echo "<p>Order Made By :".$row['email']."<br>";
	  			echo "DATE/TIME : ".$row['order_date']."<br></p>";
	  		}
		}
		public function GetallEmployee()
		{
			$DTB = dbHandler::getInstance();
			$query = "SELECT name,eid FROM employee";
			$result = $DTB->query($query);
			$html = "";
			while($row = mysql_fetch_array($result))
	  		{
	  			$eid = $row['eid'];
	  			$name = $row['name'];
	  			$html .= '<input type="radio" name = "EMP" value='.$eid.'>'.$name.'</input><br/>';
	  		}
	  		return $html;
		}
		public function AssignOrder($eid,$ordernum)
		{
			$DTB = dbHandler::getInstance();
			$query = "INSERT INTO workson VALUEs('$ordernum','$eid')";
			$result = $DTB->query($query);
			$query = "UPDATE orders SET Assign ='$eid' WHERE order_no ='$ordernum'";
			$result = $DTB->query($query);
		}
		public function getAllCompleteOrders()
		{
			$DTB = dbHandler::getInstance();
			$query = "SELECT order_no FROM orders WHERE is_Complete = 'YES'";
			$result = $DTB->query($query);
			while($row = mysql_fetch_array($result))
	  		{
	  			echo "Order # ".$row['order_no'];
	  		}
		}
		public function deleteCompleteOrder()
		{
			$DTB = dbHandler::getInstance();
			$query = "SELECT order_no FROM orders WHERE is_Complete = 'YES'";
			$result = $DTB->query($query);
			while($row = mysql_fetch_array($result))
	  		{
	  			$corderid = $row['order_no'];
	  			$query = "DELETE FROM orderitem WHERE order_no = '$corderid'";
	  			$results = $DTB->query($query);
	  		}
	  		$query = "DELETE FROM orders WHERE is_Complete = 'YES'";
			$result = $DTB->query($query);
		}
		public function updateEMPSalary($emp,$newSal)
		{
			$DTB = dbHandler::getInstance();
			$query = "UPDATE employee SET salary= '$newSal' WHERE eid='$emp'";
			$results = $DTB->query($query);
		}
		public function FiredEMP($eid)
		{
			$DTB = dbHandler::getInstance();
			$query = "DELETE FROM employee WHERE eid='$eid'";
			$results = $DTB->query($query);
		}
		public function HiredEMP($EMPname,$EMPpass,$EMPsal)
		{
			$DTB = dbHandler::getInstance();
			if($EMPname =="Name" || $EMPpass =="Password" || $EMPsal =="Started-Salary")
			{
				echo "<p>NotAllFieldIsEnter</p>";
				return;
			}
			else
			{
				$query = "INSERT INTO employee(name,salary,password) VALUE('$EMPname','$EMPsal','$EMPpass')";
				$results = $DTB->query($query);
			}
		}
	}
?>